# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=anari-sdk
pkgver=0.7.2
pkgrel=0
pkgdesc="SDK for the ANARI 3D rendering engine interface API"
url="https://github.com/KhronosGroup/ANARI-SDK"
arch="all"
license="Apache-2.0"
makedepends="cmake ninja python3 glm-dev"
subpackages="$pkgname-static $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/KhronosGroup/ANARI-SDK/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/ANARI-SDK-$pkgver"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	# render tests require a valid device
	sed -i /add_subdirectory\(render\)/d tests/CMakeLists.txt

	cmake -B build-shared -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DBUILD_SHARED_LIBS=ON \
		-DBUILD_CTS=OFF \
		-DBUILD_HELIDE_DEVICE=OFF \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		-DBUILD_EXAMPLES=OFF \
		$CMAKE_CROSSOPTS
	cmake --build build-shared

	cmake -B build-static -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DBUILD_SHARED_LIBS=OFF \
		-DBUILD_CTS=OFF \
		-DBUILD_HELIDE_DEVICE=OFF \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		-DBUILD_EXAMPLES=OFF \
		$CMAKE_CROSSOPTS
	cmake --build build-static
}

check() {
	msg "Testing shared version"
	ctest --test-dir build-shared --output-on-failure

	msg "Testing static version"
	ctest --test-dir build-static --output-on-failure
}

package() {
	# installing static first lets shared overwrite the executables so they
	# themselves are not statically linking the library
	DESTDIR="$pkgdir" cmake --install build-static
	DESTDIR="$pkgdir" cmake --install build-shared
}

sha512sums="
e54969a6b6186eb9a1d7c8ba16647ea0e54114d130947a2690fb0ed42094ea8d0fba8d289cf79b56fbae337fafc829077e9c9dddeedf5e03c3a6ca1747531dea  anari-sdk-0.7.2.tar.gz
"
